﻿package cz.dadul.adventure.controller
{
	/**
	 * ...
	 * @author Dadul
	 */
	import flash.display.*;
	import flash.events.*;
	import cz.dadul.adventure.model.*;
	import cz.dadul.adventure.view.*;
	import cz.dadul.adventure.model.events.*;
	import flash.ui.*;
	 
	 public class MouseController extends EventDispatcher
	{
		// Constants
		// Singleton instance
		private static var instance:MouseController;
		// Variables
		private var _item:PickableItem;
		private var _itemToUse:Boolean;


		public function MouseController(p_key:SingletonBlocker):void{
			// this shouldn't be necessary unless they fake out the compiler:
			 if (p_key == null) {
				throw new Error("Error: Instantiation failed: Use MouseController.getInstance() instead of new.");
			  }
			  init();
		}
		
		/*
		 * Public
		 */ 
		public function startDrag(item:PickableItem):void {
			this._item = item;
			this._itemToUse = true;
			item.startDrag();
			Mouse.hide();
		}
		 
		public function stopDrag():void {
			this._itemToUse = false;
			this._item.stopDrag();
			this._item = null;
		}
		
		public function enablePointer():void {			
			Mouse.show();
		}
		
		public function disablePointer():void {
			Mouse.hide();
		}
		/*
		 * SETTERS / GETTERS
		 */ 
		public function get draggedItem():PickableItem {
			return _item;
		}
		 
		 
		/**
		 * PRIVATE
		 */
		private function init():void { 
			_itemToUse = false;
		}

		
		
		/**
		 * STATIC
		 */
		public static function getInstance():MouseController {
         if (instance == null) {
            instance = new MouseController(new SingletonBlocker());
          }
         return instance;
		}

	}
	
}

internal class SingletonBlocker {}